package noppes.vc.client;

import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.texture.ITextureObject;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.IResourceManager;
import net.minecraft.client.resources.IResourceManagerReloadListener;
import net.minecraft.client.resources.SimpleReloadableResourceManager;
import net.minecraft.util.ResourceLocation;

public class VCResourceLoader implements IResourceManagerReloadListener {
   public void onResourceManagerReload(IResourceManager var1) {
      if (var1 instanceof SimpleReloadableResourceManager) {
         this.createTextureCache();
      }

   }

   private void createTextureCache() {
      this.enlargeTexture("planks_oak");
      this.enlargeTexture("planks_big_oak");
      this.enlargeTexture("planks_birch");
      this.enlargeTexture("planks_jungle");
      this.enlargeTexture("planks_spruce");
      this.enlargeTexture("planks_acacia");
      this.enlargeTexture("iron_block");
      this.enlargeTexture("diamond_block");
      this.enlargeTexture("stone");
      this.enlargeTexture("gold_block");
      this.enlargeTexture("wool_colored_white");
   }

   private void enlargeTexture(String texture) {
      TextureManager manager = Minecraft.getMinecraft().getTextureManager();
      if (manager != null) {
         ResourceLocation location = new ResourceLocation("variedcommodities", "textures/cache/" + texture + ".png");
         ITextureObject ob = manager.getTexture(location);
         if (ob == null || !(ob instanceof VCResourceLoader$TextureCache)) {
            ob = new VCResourceLoader$TextureCache(this, location);
            manager.loadTexture(location, ob);
         }

         ((VCResourceLoader$TextureCache)ob).setImage(new ResourceLocation("textures/blocks/" + texture + ".png"));
      }
   }
}
